def is_prime(a):
    if a <= 1:
        return False
    for b in range(2, int(a*0.5) + 1):
        if a % b == 0:
            return False
    return True
def max_prime(number):
    if len(str(number)) != 4 or number <=0:
        return 0
    str_number = str(number)
    primes = []
    for b in range(4):
        for c in range(b + 1, 5):
            num = int(str_number[b:c])
            if is_prime(num):
                primes.append(num)
    if primes:
        return max(primes)
    else:
        return 0
number = int(input())
print(max_prime(number))